import React from 'react';
import {
    WeaDialog,
    WeaLocaleProvider,
    WeaTop,
    WeaRightMenu,
    WeaSearchGroup,
    WeaTools,
    WeaFormItem,
    WeaSwitch,
    WeaNewScroll,
    WeaTable
} from 'ecCom';
import {Button, Input, Modal, Spin} from 'antd';

import {inject, observer} from 'mobx-react';
import {toJS} from "mobx";

const getLabel = WeaLocaleProvider.getLabel;

@inject("myParame", "initializationForm")
@observer
class Initialization extends React.Component {

    render() {
        let {myParame, title, initializationForm} = this.props;
        let {setShowInitialization} = myParame
        let {setInitialization, loading} = initializationForm;

        let diabtns = [
            (<Button type="primary" disabled={loading} onClick={() => {
                setInitialization();
            }}>{getLabel(20873, "初始化")}</Button>),
            (<Button type="ghost" disabled={loading} onClick={() => {
                setShowInitialization(false);
            }}>{getLabel(309, "关闭")}</Button>)
        ]

        let dropmenubtn = [
            {
                key: '1',
                disabled: loading,
                icon: <i className="icon-coms-Synchro"/>,
                content: getLabel(20873, "初始化"),
                onClick: () => setInitialization(),
            }, {
                key: '2',
                disabled: loading,
                icon: <i className="icon-coms-Collection"/>,
                content: getLabel(28111, "收藏"),
                onClick: () => myParame.setVisiblecollect(),
            }
        ]
        {/*弹框*/}
        return (
        <WeaDialog
            visible={true}
            style={{width: 1000, height: 600}}
            title={title}
            maskClosable={false}
            onCancel={() => setShowInitialization(false)}
            buttons={diabtns}
        >
            <Spin spinning={loading} style={{height: "100%", overflow: "auto"}}>
                {/*右键菜单*/}
                <WeaRightMenu datas={dropmenubtn}>
                    <WeaNewScroll ref="scroll" style={{height: "100%", overflow: "auto"}}>
                        {/*基本信息*/}
                        {this.getBaseFormWea()}
                        {this.getFormWea()}
                    </WeaNewScroll>
                </WeaRightMenu>
            </Spin>
        </WeaDialog>
    )
    }

    /**、
     *
     * 获取初始化说明
     * @returns {*}
     */
    getBaseFormWea = () => {
        //这里数据就可以走接口了
        let itemmap = [
            getLabel("501281", "初始化与契约锁相关的自定义浏览按钮"),
            getLabel("501282", "初始化与契约锁相关的计划任务"),
            getLabel("501283", "初始化与契约锁相关的action")];
        let items = [];
        items.push({
            com: (<WeaFormItem
                label={``}
                labelCol={{span: 0}}
                tipPosition="bottom"
                wrapperCol={{span: 24}}>
                {<div>
                    <b className={"lockmarg-10"}>{getLabel("501280", "初始化内容")}</b>
                    <ol>
                        {itemmap && itemmap.map(index => {
                            return <li className={"lockmarg-10 indexcss"}>{index}</li>
                        })}
                    </ol>
                </div>}
            </WeaFormItem>),
            col: 1,
        });
        return (<WeaSearchGroup title={getLabel("501279", "初始化说明")} items={items} showGroup={true}/>);
    }

    /**
     * 获取初始化结果
     * @returns {Array}
     */
    getFormWea = () => {
        const {initializationForm} = this.props;
        const {dateresult} = initializationForm
        let group = [];
        let items = [];
        const columns = [{
            // title: '主题1',
            title: getLabel(500401, "类型"),
            dataIndex: 'type',
            key: 'type',
            width: "30%",
            sorter: false,
        }, {
            title: getLabel(32940, "日志信息"),
            dataIndex: 'msglog',
            key: 'msglog',
            width: "20%",
            sorter: false
        }];

        items.push({com: <WeaTable columns={columns} dataSource={toJS(dateresult)} pagination={false}/>, col: 1})
        group.push(<WeaSearchGroup needTigger={true} title={getLabel(501592, "初始化结果")} showGroup={true} items={items}/>)
        return group;
    }

}

export {Initialization}